/*
 ============================================================================
 Name        : IODevice.h
 Author      : James McQueen, Corwyn Simpson, Craig Markham
 Version     :
 Date        : 05/14/2012
 Description : TCSS-422 Operating Systems Scheduler
 ============================================================================
 */

#ifndef __IODEVICE__
#define __IODEVICE__

#include <pthread.h>
#include "ringbuff.h"
#include "CPU.h"

#define IO_RANDOM 1
#define IO_STEADY 0

#define IODEVICE_KBD 3
#define IODEVICE_VID 2
#define IODEVICE_DISK 1
#define IODEVICE_TIMER 0

/*-------------------- IO Device --------------------*/
typedef struct
{
    CPU* cpu;
    int device_num;
    int interval;
    int randomness_flag;
    int is_enabled;
} IODevice;


/********************* IO Device Functions *********************/

/* Makes a new IODevice that is connected to cpu with an average interval
 * that interrupts are triggered. If is_random is true (IO_RANDOM), it will
 * trigger at random intervals that will average out to the interval
 */
IODevice* iodevice_init(CPU* cpu, int device_num, int interval, int is_random);
void iodevice_reinit(IODevice* io, CPU* cpu, int device_num, int interval, int is_random);
int iodevice_getDeviceNum(IODevice* io);
int iodevice_getInterval(IODevice* io);
int iodevice_isRandom(IODevice* io);
int iodevice_isEnabled(IODevice* io);

void iodevice_setEnabled(IODevice* io, int enabled);
void iodevice_toggleEnabled(IODevice* io);

/* Generates interrupts at regular or semi-regular intervals 
 * Should be run as it's own thread 
 */
void* iodevice_run(void* io);

#endif /* IODEVICE_H_ */
